/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package taglibs;

import daos.CategoryDAO;
import daos.ItemDAO;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import models.Category;
import models.Item;

/**
 *
 * @author trietto
 */
public class BookDetail extends TagSupport {

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    /*
     * (non-Javadoc)
     * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
     */
    public int doStartTag() {
        try {
            JspWriter writer = pageContext.getOut();
            int itemId = Integer.parseInt(pageContext.getRequest().getParameter("itemid"));
            Item item = ItemDAO.singleton().select(itemId);

            if (item == null) {
                return SKIP_BODY;
            }
            Category category = CategoryDAO.singleton().select(item.getCategoryId());

            writer.println("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
            writer.println("<tr>");
            writer.println("<td colspan='2' align='center'><b>BOOK DETAILS</b><br></td>");
            writer.println("</tr>");

            writer.println("<tr>");
            writer.println("<td>Title:</td>");
            writer.println("<td><a href='BookDetail.jsp?itemid=" + item.getItemId() + "'>"
                    + item.getName());
            writer.println("</a></td>");
            writer.println("</tr>");

            writer.println("<tr>");
            writer.println("<td>Author:</td>");
            writer.println("<td>");
            writer.println(item.getAuthor());
            writer.println("</td>");
            writer.println("</tr>");

            writer.println("<tr>");
            writer.println("<td>Category:</td>");
            writer.println("<td>" + category.getName());
            writer.println("</td>");
            writer.println("</tr>");

            writer.println("<tr>");
            writer.println("<td>Price:</td>");
            writer.println("<td>" + item.getPrice());
            writer.println("</td>");
            writer.println("</tr>");

            writer.println("<tr>");
            writer.println("<td>Image URL:</td>");
            writer.println("<td>");
            writer.println("<img alt='' src='" + item.getImageURL() + "' />");
            writer.println("</td>");
            writer.println("</tr>");

            writer.println("<tr>");
            writer.println("<td>Notes:</td>");
            writer.println("<td>" + item.getNotes());
            writer.println("</td>");
            writer.println("</tr>");

            writer.println("<tr>");
                writer.println("<td colspan='2'><a href='ShoppingCartServlet?itemid="+item.getItemId()
                        +"'>Add to Cart</a>");
                writer.println("</td>");
                writer.println("</tr>");

            writer.println("</table>");
        } catch (Exception e) {
        }
        return SKIP_BODY;
    }
}
